package com.emser.unc.client.view;

import com.emser.unc.client.CloudMobile;
import com.emser.unc.client.presenter.MenuPresenter;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.ToggleButton;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;

public class MenuView extends Composite implements MenuPresenter.Display {	
	private ToggleButton btnTemp = null;
	private ToggleButton btnSellers;
	private ToggleButton btnCustomers;
	private ToggleButton btnDevices;
	private ToggleButton btnReports;
	private ToggleButton btnProducts;
	private int heightsimplePanel;
	private VerticalPanel verticalPanel_2;
	
	public MenuView() {
		VerticalPanel verticalPanel = new VerticalPanel();
		verticalPanel.setStyleName("gwt-VPanelCenter");
		initWidget(verticalPanel);
		verticalPanel.setSize("100%", CloudMobile.get().getHeightPanelCenter() + "px");	
		heightsimplePanel = CloudMobile.get().getHeightPanelCenter() - 40;
		SimplePanel simplePanel = new SimplePanel();
		simplePanel.setStyleName("gwt-SimplePanelM1");
		verticalPanel.add(simplePanel);
		verticalPanel.setCellHeight(simplePanel, "40px");
		verticalPanel.setCellWidth(simplePanel, "100%");
		simplePanel.setSize("100%", "38px");
		
		verticalPanel_2 = new VerticalPanel();
		verticalPanel_2.setStyleName("gwt-VPanelEast");
		verticalPanel.add(verticalPanel_2);
		verticalPanel.setCellHeight(verticalPanel_2, heightsimplePanel+"px");
		verticalPanel.setCellWidth(verticalPanel_2, "200px");
		verticalPanel_2.setSize("100%", "100%");
		VerticalPanel verticalPanel_1 = new VerticalPanel();
		verticalPanel_2.add(verticalPanel_1);
		verticalPanel_2.setCellWidth(verticalPanel_1, "100%");
		verticalPanel_1.setStyleName("get-VPanelMenu");
		verticalPanel.setCellHorizontalAlignment(verticalPanel_1, HasHorizontalAlignment.ALIGN_CENTER);
		verticalPanel.setCellHeight(verticalPanel_1, "150px");
		verticalPanel.setCellWidth(verticalPanel_1, "200px");
		verticalPanel_1.setSize("100%", "150px");
		
		btnSellers = new ToggleButton("Vendedores");
		verticalPanel_1.add(btnSellers);
		verticalPanel_1.setCellHeight(btnSellers, "30px");
		btnSellers.setHeight("18px");
		
		btnCustomers = new ToggleButton("Clientes");
		verticalPanel_1.add(btnCustomers);
		verticalPanel_1.setCellHeight(btnCustomers, "30px");
		btnCustomers.setHeight("18px");
		
		btnDevices = new ToggleButton("Dispositivos");
		verticalPanel_1.add(btnDevices);
		verticalPanel_1.setCellHeight(btnDevices, "30px");
		btnDevices.setHeight("18px");
		
		btnProducts = new ToggleButton("Productos");
		verticalPanel_1.add(btnProducts);
		verticalPanel_1.setCellHeight(btnProducts, "30px");
		btnProducts.setHeight("18px");
		
		btnReports = new ToggleButton("Reportes");
		verticalPanel_1.add(btnReports);
		verticalPanel_1.setCellHeight(btnReports, "30px");
		btnReports.setHeight("18px");
		SimplePanel simplePanel_1 = new SimplePanel();
		verticalPanel_2.add(simplePanel_1);
		verticalPanel_2.setCellWidth(simplePanel_1, "100%");
		verticalPanel_2.setCellHeight(simplePanel_1, "100%-160px");
		simplePanel_1.setSize("100%", "100%");
		
	}
	
	@Override
	public Widget asWidget() {
	    return this;
	}

	@Override
	public HasClickHandlers getBtnSellers() {
		return btnSellers;
	}

	@Override
	public HasClickHandlers getBtnCustomers() {
		return btnCustomers;
	}

	@Override
	public HasClickHandlers getBtnDevices() {
		return btnDevices;
	}

	@Override
	public HasClickHandlers getBtnProducts() {
		return btnProducts;
	}

	@Override
	public HasClickHandlers getBtnReports() {
		return btnReports;
	}

	@Override
	public void repaintBtn(ClickEvent event) {
		ToggleButton btn = (ToggleButton) event.getSource();
		if (btn.isDown()) {
			if(btnTemp == null)
				btnTemp = btn;
			else  if(!btnTemp.equals(btn)){
	        	  btnTemp.setDown(false);
	        	  btnTemp = btn;
	        }	  
	     }else {
	        btn.setDown(true);
	     }
	}	
}
